 VideoJS.setupAllWhenReady();
$(document).ready(function() {
//  $('.addTags').bind('submit', function(event) {
////      alert($.serialize(event));
//        event.preventDefault();
////        alert($(this).serialize()+"&ajax=true");
//        var temp = $(this).serialize()+"&ajax=true";
//         var m= this.parentNode.parentNode.id;
//
//        $.post("/urp/tags/add/", temp, function(data) {
//            
//            reloadComments(m);
//        });
//      
//    });
if (document.URL.indexOf('#')!=-1)
    {
         var alpha = document.URL.substring(document.URL.indexOf('#')+1)+'ab';
         
         if (alpha!="ab")
            var m=setTimeout('document.getElementById("'+alpha+'").scrollIntoView(true)', 200);
//         alert(document.getElementById(alpha));
        }

$(".tags2 div").live('hover', function(event) {
//    alert(event.target);

  if (event.type != "mouseleave") {
    var thing = String(event.target.innerHTML);
   
//    alert(thing);
    if (!document.getElementById('hoveringTag')) {
        var element = document.createElement('div');
        element.id='hoveringTag';
        document.body.appendChild(element);
        }
//        alert(thing);
//    document.getElementById('hoveringTag').innerHTML=data;
//alert(thing);
     var y = document.getElementById('hoveringTag');
     
     this.appendChild(y);
//     alert(this.innerHTML);
       $(y).load('/urp/tags/view_description/'+thing, function () {
//                document.getElementById('hoveringTag').innerHTML += thing;

                   
                   m=$(event.target).offset();
                   y.style.left='auto';
                   y.style.right='auto';
                   y.style.display='block';
//                   alert(window.screen.width - y.style.width);   
                  
                   if (window.screen.width - 160 >= m.left)
                           y.style.left= m.left+'px';
                   else
                           y.style.right = '10px';
                       
                   y.style.top=m.top+15+'px';
                   y.innerHTML+="<br/><a href='/urp/tags/view/"+thing+"'>" + thing + "'s wiki page</a>";
                   
                 
       });
      }  else {
//          if (!$(".hoveringTag").hasClass('hovering'))

              document.getElementById('hoveringTag').innerHTML='';
              document.getElementById('hoveringTag').style.display='none';
       }
     });
//$(".hoveringTag").live('hover', function(event) {
//   if (event.type != "mouseleave") {
//       $(".hoveringTag").addClass('hovering');
//       }
//       else { 
//           $(".hoveringTag").removeClass('hovering');
//           this.style.display='none';
//           }
//   
//   });
     



$(".addTags").live('submit', function(event) {
//      alert($.serialize(event));
        event.preventDefault();
//        alert($(this).serialize()+"&ajax=true");
        var temp = $(this).serialize()+"&ajax=true";
         var m= this.parentNode.parentNode.id;
       if (!this.suggest.checked) {
        $.post("/urp/tags/add/", temp, function(data) {
            
            reloadComments(m);
        });
        }
        else {
                 this.tagSubmit.style.display='none';
                 this.style.opacity = 5/10;
                 this.style.filter = 'alpha(opacity=' + 5*10 + ')';   
                 var suggest1=$(this.parentNode).find('#suggest1');
                 $(suggest1).html('');
                 var y=this;
                 $.post("/urp/tags/suggest/", this.Tagtag.value, function(data) {
                       
                        if (data!="") {
                            y.style.opacity = 10/10;
                            y.style.filter = 'alpha(opacity=' + 10*10 + ')'; 
                            y.suggest.checked=false;
                            y.tagSubmit.style.display='block';
    //                        y.suggesta.style.display='none';
                            $(suggest1).html("Possible related tags: "+ data);
                        }
                        else {
                             $.post("/urp/tags/add/", temp, function(data) {
                                reloadComments(m);
                            });
                            }
                        });
            }
});



//

});

//function scrollToComment(alpha)
//{
//    
//    }

function showHide(i)
{
    if (i.nextSibling.style.display=='none')
     i.nextSibling.style.display='block';
    
    
    }

function imageClick(i)
{
     
    var y = i.src.replace('filter/small','transfer');
   
    window.location=y;
}
function editParents()
{
    document.getElementById('editParents').style.display='block';
    return false;
    }
function editDescription()
{
    document.getElementById('editDescription').style.display='block';
    return false;
    }

function setChildren()
{
    document.getElementById('setChildren').style.display='block';
    return false;
    }
 function showChildComments(i,y)
 {
 
//     alert(y.parentNode.parentNode.parentNode.innerHTML);
//     
    var m = y.parentNode.parentNode.parentNode;
    m.style.opacity = 5/10;
    m.style.filter = 'alpha(opacity=' + 5*10 + ')'; 
         $(m).load('/urp/comments/view/'+i, function () {
        m.style.opacity = 10/10;
    m.style.filter = 'alpha(opacity=' + 10*10 + ')'; 
	   
    }
    );
     return false;
     
     }
    
function showChildren(i)
{
    if (i.innerHTML== 'Show All') {
        $('.hoverTag').attr('class','hoverTag1');
        i.innerHTML='Hide All';
        }
    else {
        $('.hoverTag1').attr('class','hoverTag');
         i.innerHTML='Show All';
        }
    }
function addChildren1()
{
//    $('#comments').load('/urp/tags/children/'+i, function () {
//        document.getElementById('comments').style.opacity = 10/10;
//	document.getElementById('comments').style.filter = 'alpha(opacity=' + 10*10 + ')';    
//    }
//    );
        document.getElementById('children').style.opacity = 5/10;
        document.getElementById('children').style.filter = 'alpha(opacity=' + 5*10 + ')';   
        $.post("/urp/tags/setparent/", $('#setparent').serialize()+'&ajax=true', function(data) {
            document.getElementById('children').style.opacity = 10/10;
            document.getElementById('children').style.filter = 'alpha(opacity=' + 10*10 + ')';    
            document.getElementById('children').innerHTML=data;
//            $('#comments').load('/urp/posts/onchange/'+i+'/'+y.options[y.selectedIndex].value, function () {
//               document.getElementById('comments').style.opacity = 10/10;
//               document.getElementById('comments').style.filter = 'alpha(opacity=' + 10*10 + ')';    
//            }
//            );
        });
    return false;
    }

//function rebind()
//{
//      $('.addTags').bind('submit', function(event) {
////      alert($.serialize(event));
//        event.preventDefault();
////        alert($(this).serialize()+"&ajax=true");
//        var temp = $(this).serialize()+"&ajax=true";
//         var m= this.parentNode.parentNode.id;
//
//        $.post("/urp/tags/add/", temp, function(data) {
//            
//            reloadComments(m);
//        });
//      
//    });
//    }








var replies=0;
function reply(i,y)
{
//    alert(y.parentNode.nextSibling.innerHTML);
    if (y.parentNode.nextSibling.id=="px-widget-1" || y.parentNode.nextSibling.id=="mycomment")
        return;
    //clone then put below.
    
    $('#px-clear').click();
    var p=document.getElementById("mycomment");
    
    var p1 = p.cloneNode(true);
    var p2 = document.getElementById("px-widget-1");
    document.getElementById('textual').removeAttribute('id');
    $(p1).find('.texting').attr('id','textual');
    p1.firstChild.firstChild.nextSibling.value=i;
//    alert(p1.lastChild.lastChild.style);

   $(p1).find('.cancel1').css("display","inline");
   
    $(p1).insertAfter(y.parentNode);
    p1.parentNode.insertBefore(p2,p1);
    
 //       $(p1).insertAfter(y.parentNode);
//   $(p1).find('#CommentReply').attr('value', i);
//      $(p1).find('.cancel').css('display','inline');
    
//     y.parentNode.parentNode.insertBefore(p,    y.parentNode.nextSibling);
//    document.getElementById('ReplyingTo').innerHTML="<i> Replying to Comment Number " + i +"</i>";

    }
    
var login_timeout;
function loginBar(i) {
clearTimeout(login_timeout);
document.getElementById('loginBar').style.display="block";
return false;
}
function loginBar1(i){
   
    login_timeout=setTimeout("document.getElementById('loginBar').style.display='none';",500);
    
    }

function updown(i,n, y)
{

    if (n==1) 
        $.get("/urp/comments/up/"+i, function(data){
         
});
    else
         $.get("/urp/comments/down/"+i, function(data){
});
  
    y.parentNode.previousSibling.lastChild.innerHTML=parseInt(y.parentNode.previousSibling.previousSibling.innerHTML)+n;
 }
function showhide(i)
{
//    alert(i.nextSibling.innerHTML);
    if (i.nextSibling.style.display=='none') {
            i.nextSibling.style.display="inline";
            i.innerHTML='Hide Options';
            }
    else {
        i.nextSibling.style.display='none'
        i.innerHTML='Options';
        }
    }
function onChange(i,y)
{ 
//    alert('/urp/posts/onchange/'+i+'/'+y.options[y.selectedIndex].value);

    	document.getElementById('comments').style.opacity = 5/10;
	document.getElementById('comments').style.filter = 'alpha(opacity=' + 5*10 + ')';
    $('#comments').load('/urp/posts/onchange/'+i+'/'+y.options[y.selectedIndex].value, function () {
        document.getElementById('comments').style.opacity = 10/10;
	document.getElementById('comments').style.filter = 'alpha(opacity=' + 10*10 + ')';   
         VideoJS.setupAllWhenReady();
}
);
    }
    
    function showOptions(i)
    {
        i.nextSibling.nextSibling.style.display='inline';
        i.style.display='none';
        }
        
        function deleteComment(i, m)
        {
            
//           if (document.getElementById('deleteWhich').value;
               
                                var y=document.getElementById('deleteComment');
                 y.style.display='block';

            if (m!=document.getElementById('deleteCommentId').value)
                {
                  document.getElementById('deleteCommentId').value=m;
                  $(y).offset( $(i).offset());
            }
             
//              alert(m.left);
//              alert(m.top);
//              y.style.left=left;
//              y.style.top=top;
              
            }
            function editComment(i)
            {
                i.parentNode.parentNode.previousSibling.style.display='none';
                var y =document.getElementById("editComment");
                y.style.display='block';
                i.parentNode.parentNode.parentNode.insertBefore(y,i.parentNode.parentNode.previousSibling);
                
                }
            function hideDelete(i)
            {
                i.parentNode.style.display='none';
//                i.parentNode.style.top='0px';
//                i.parentNode.style.left='0px';
                }
function onBoardChange(i,y)
{
        	document.getElementById('posts').style.opacity = 5/10;
	document.getElementById('posts').style.filter = 'alpha(opacity=' + 5*10 + ')';
    $('#posts').load('/urp/boards/onchange/'+i+'/'+y.options[y.selectedIndex].value, function () {
        document.getElementById('posts').style.opacity = 10/10;
	document.getElementById('posts').style.filter = 'alpha(opacity=' + 10*10 + ')';    
}
);
    
    }

    
    
function disablelets()
{
    document.getElementById("postsDisinclude").disabled=true;
     document.getElementById("postsAny").disabled=true;
    }
function searching()
{
    $('#search1').click(); 
    return false;
    
    }
    
function advanced1(i) {
//    alert(i);
    
    if (i.checked==true) {
        i=i.parentNode;
        document.getElementById('search').style.height='75px';
//        document.getElementById('flashMessage').style.margin='0px';
        i.nextSibling.style.display="block";
        if (document.URL.indexOf('viewas=1')==-1)
            document.getElementById('advanced').style.width='70%';
        }
    else {
        i=i.parentNode;
        document.getElementById('search').style.height='30px';
//        document.getElementById('flashMessage').style.margin='auto';
         i.nextSibling.style.display="none";
          if (document.URL.indexOf('viewas=1')==-1)
             document.getElementById('advanced').style.width='100%';
        }
    }
function preclude(i)
{
//    alert(i.innerHTML);
//if (i.value.length>50)
//    i.style.height='100px';

document.getElementById('postsDisinclude').value="";
document.getElementById('postsAny').value="";
    if (i.value.indexOf("-")!=-1 || i.value.indexOf("+")!=-1)
        {
            
            y=i.value.split(' ');
            for (m=0; m < y.length; m++) {
                if (y[m].indexOf('-')==0)
                  document.getElementById('postsDisinclude').value+=y[m].substring(1) + " ";
                else if (y[m].indexOf('+')==0) {
                  document.getElementById('postsAny').value+=y[m].substring(1) + " ";
                }
                    }
//             var regex = new RegExp('/(?!\b[a-c]+\b)\b\w+\b/');
//            alert( document.getElementById('postsDisinclude').value.replace(regex, ' '));
             
//             var re5 = new RegExp('([^<\/]|^)' + '-', 'gi');
//            alert( document.getElementById('postsDisinclude').value.replace(re5, '$1'));
        }        
    }
function preclude1(i,n)
{
//alert(i.value);
var newvalue="";
var d=" "+n;

var y=i.value.replace(/ /g,d);
//alert(y);
//alert(y);
l=document.getElementById('search').value.split(' ');
//document.getElementById('search').value
var z="";
for (m=0; m < l.length; m++)
        if (l[m].indexOf(n)!=0)
            z+=l[m]+" ";
if (i.value!="")
    document.getElementById('search').value=z+n+y;
}


function cancel(i)
{
    $('px-clear').click();
 document.getElementById('smash1').appendChild(i.parentNode.parentNode.previousSibling);
    i.parentNode.parentNode.parentNode.removeChild(i.parentNode.parentNode);
//    document.getElementById('textual').removeAttribute('id');
     $('#mycomment').find('.texting').attr('id','textual');
     
    
 }
function comment(i)
{
    document.getElementById('textual').readOnly=true;
    if (document.getElementById('submitting'))
         document.getElementById('submitting').removeAttribute('id');   
    i.setAttribute('id','submitting');   
   
//    i.previousSibling.lastChild.setAttribute('id','textual');
    $('#px-submit').click();
//    document.getElementById('textual').disabled=true;


 }
 function setTextual(i)
 {
//     if ( document.getElementById('textual'))
//     document.getElementById('textual').id='';
//    if (document.getElementById('textual')!=null)
//     document.getElementById('textual').id='';
////     alert(i.parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML);
//    alert(i.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML);
//     var thing=$(i).closest("#post1");
////     thing=thing.parentNode;
//     $(thing).find('.texting').attr('id','textual');
//        alert(i.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.lastChild.innerHTML);
     }
 
 function comment1()
 {
//       alert('tim');

        if (document.getElementById('textual').value=="")
        {
            document.getElementById('textual').readOnly=false;
            return;
        }
       document.getElementById("smash1").appendChild(document.getElementById("px-widget-1"));
       $('#mycomment').find('.texting').attr('id','textual');
     var i=document.getElementById('submitting');
//     alert(i.id);
     var y=document.getElementById('postId').value;
//     alert(y);
        document.getElementById('comments').style.opacity = 5/10;
	document.getElementById('comments').style.filter = 'alpha(opacity=' + 5*10 + ')';
//        alert('tim');
      var m = document.getElementById('SortPost');
//      alert((i.parentNode.innerHTML));
//document.getElementById('textual').disabled=false;
      $.post("/urp/comments/add/"+y+"/"+m.options[m.selectedIndex].value, $(i.parentNode).serialize(), function(data) {
//          document.getElementById('textual').disabled=true;
          document.getElementById('comments').innerHTML=data;
                  document.getElementById('comments').style.opacity = 10/10;
	document.getElementById('comments').style.filter = 'alpha(opacity=' + 10*10 + ')';    
//          alert(document.getElementById('textual').value);
//          var textual =document.getElementById('textual').value;
//          document.getElementById('textual').value='';
//          $("div:contains('"+textual+"')").css("text-decoration", "underline");
// document.getElementById('newcomment').style.backgroundColor='#FFD700';
        var newcomment= document.getElementById('newcomment').innerHTML+"ab";
         
            document.getElementById(newcomment).style.backgroundColor='#ffff99';
              $('html,body').animate({
//                scrollTop:  $('#mycomment').offset().top},
                 
                  scrollTop: $("#"+newcomment).offset().top-15},
                'slow', function() { 
//                $("#"+document.getElementById('newcomment').innerHTML+"ab").fadeTo(0.5,"slow", function () {
//                  $(this).css("background-color", "white");
//                  $(this).fadeIn("slow");
//                });
//                 $("#"+newcomment).animate({ backgroundColor: "#ffffff" }, 800)
                  $("#"+newcomment).animate({'backgroundColor' : '#ffffff'}, 2000);

        });
               
          });
//          document.getElementById('textual').disabled=false;
          
//          i.removeAttribute('id');
//          i.previousSibling.lastChild.removeAttribute('id');
           document.getElementById('textual').readOnly=false;
     }
 
function editTags(i)
{
    if ( i.innerHTML!="[Cancel]") {
    i.innerHTML="[Cancel]";
    i.nextSibling.nextSibling.style.display='inline-block';
    }
    else
        {
                i.innerHTML="[Edit]";
                i.nextSibling.nextSibling.style.display='none';
            }
}
function editTags1(i)
{
      if ( i.innerHTML!="[Cancel]") {
    i.innerHTML="[Cancel]";
    document.getElementById('tags').style.display='inline-block';
    }
    else
        {
                            i.innerHTML="[Edit]";
                 document.getElementById('tags').style.display='none';
            }
    }
function showTags(i)
{
    i.style.display="none";
    i.nextSibling.style.display="block";
}
function reloadComments(m)
{
    
   var i=document.getElementById('postId').value;
   var y=document.getElementById('SortPost');
   document.getElementById('comments').style.opacity = 5/10;
   document.getElementById('comments').style.filter = 'alpha(opacity=' + 5*10 + ')';
    $('#comments').load('/urp/posts/onchange/'+i+'/'+y.options[y.selectedIndex].value, function () {
       
        document.getElementById('comments').style.opacity = 10/10;
	document.getElementById('comments').style.filter = 'alpha(opacity=' + 10*10 + ')';   
        document.getElementById(m).style.backgroundColor='#ffff99';
        $('html,body').animate({scrollTop: $("#"+m).offset().top-15},
                'slow', function() { 
                  $("#"+m).animate({'backgroundColor' : '#ffffff'}, 2000);

        });
      });
        
    }
    
    
  